import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Remove implements ActionListener {

	public void actionPerformed (ActionEvent e){
		int i;
		ArrayList<String> list = new ArrayList<String>();
		Leitor leitor = new Leitor();
		for(i=0;leitor.ler("!TUDO",Biblioteca.arquivo + ".txt")[i]!=null;i++){
			list.add(leitor.ler("!TUDO",Biblioteca.arquivo + ".txt")[i]);
		}
		new File(Biblioteca.arquivo + ".txt").delete();
		Biblioteca.data.remove(Biblioteca.data.indexOf(Biblioteca.list.getSelectedValue()));
		if (Biblioteca.lista.equals("raiz"))
			list.remove(list.indexOf(Biblioteca.list.getSelectedValue()));
		else{
			System.out.println(Biblioteca.lista + Biblioteca.list.getSelectedValue());
			list.remove(list.indexOf(Biblioteca.lista + "<" + Biblioteca.list.getSelectedValue()));
		}
		System.out.println(Biblioteca.list.getSelectedValue());
    	try {
			FileWriter writer = new FileWriter(Biblioteca.arquivo + ".txt",true);
			for(i=0;i<list.size();i++){
				writer.write(list.get(i).toString() + "\n");
			}
			Biblioteca.list.setListData(Biblioteca.data.toArray());
			writer.close();
			
		} catch (IOException e1) {
			e1.printStackTrace();
		} 
		}
	}